<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Elisa3: sensors.h File Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Elisa3
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('sensors_8h.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">sensors.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Sensors module.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdlib.h&gt;</code><br/>
<code>#include &lt;math.h&gt;</code><br/>
<code>#include &quot;<a class="el" href="variables_8h_source.html">variables.h</a>&quot;</code><br/>
<code>#include &lt;avr\io.h&gt;</code><br/>
<code>#include &quot;<a class="el" href="leds_8h_source.html">leds.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="twimaster_8h_source.html">twimaster.h</a>&quot;</code><br/>
</div>
<p><a href="sensors_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a11b381faabbecc0143d11cf09e955462">calibrateSensors</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Calibrate all the sensors (proximity, ground and accelerometer). Pay attention for the robot to be positionated in a flat surface and that no objects obstruct the sensors. Peripherals need to be already initialized before calling this function.  <a href="#a11b381faabbecc0143d11cf09e955462"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a3d961b25677384479fcd0d413da8ef83">initAccelerometer</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Test which device is mounted on the robot and configure it.  <a href="#a3d961b25677384479fcd0d413da8ef83"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#afe99cfb7d3e16bf36cc5d29da66ce8bc">initADXL345</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Configure the ADXL345 accelerometer (2g sensitivity, 10 bits resolution).  <a href="#afe99cfb7d3e16bf36cc5d29da66ce8bc"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a00ac3777f39d082d583911fcedd3a302">initMMA7455L</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Configure the MMA74565L accelerometer (2g sensitivity, 10 bits resolution).  <a href="#a00ac3777f39d082d583911fcedd3a302"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a9c7a0d4e693d6dd1fef72e28353324a1">readAccelXY</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Request the X and Y values (10 bit data, 2's complement) and save them in their respective global variables accX and accY.  <a href="#a9c7a0d4e693d6dd1fef72e28353324a1"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#ab3ef74e35beb0d06aefb2830ff49862d">readAccelXYZ</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Request the X, Y and Z values (10 bit data, 2's complement) and save them in their respective global variables accX, accY and accZ.  <a href="#ab3ef74e35beb0d06aefb2830ff49862d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a2d993650e0a974e422727cb262f782ad">readAccelXYZ_1</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#ab53b8f8a6ca993a60fc2377d0bfd2476">readAccelXYZ_2</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="sensors_8h.html#a12fc697a01e1d04b91df358a472b5b84">computeAngle</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Compute the angle of the robot using the X and Y axes; the resulting angle is saved in the global variable "currentAngle". The angle refers to a classical reference system where the 0 points to the right, 90 to the top, 180 to the left and 270 to the bottom in a vertical wall. In order for the angle to be computed correctly, the robot has to be calibrated leaving it flat on the ground. Moreover this function update the robot motion plane (horizontal or vertical) based on the Z axis; this information is then used to switch between horizontal and vertical speed controller.  <a href="#a12fc697a01e1d04b91df358a472b5b84"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Sensors module. </p>
<dl class="author"><dt><b>Author:</b></dt><dd>Stefano Morgani &lt;<a href="mailto:stefano@gctronic.com">stefano@gctronic.com</a>&gt; </dd></dl>
<dl class="version"><dt><b>Version:</b></dt><dd>1.0 </dd></dl>
<dl class="date"><dt><b>Date:</b></dt><dd>01.02.12 </dd></dl>
<dl class="copyright"><dt><b>Copyright:</b></dt><dd>GNU GPL v3</dd></dl>
<p>General module that contains functions to interact with the sensors mounted on the robot (proximity, ground, accelerometer). The I2C communication is initialized to work with the accelerometer. There are functions to work with both the Freescale MMA7455 and the Analog Device ADXL345 accelerometers. </p>
</div><hr/><h2>Function Documentation</h2>
<a class="anchor" id="a11b381faabbecc0143d11cf09e955462"></a><!-- doxytag: member="sensors.h::calibrateSensors" ref="a11b381faabbecc0143d11cf09e955462" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#a11b381faabbecc0143d11cf09e955462">calibrateSensors</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Calibrate all the sensors (proximity, ground and accelerometer). Pay attention for the robot to be positionated in a flat surface and that no objects obstruct the sensors. Peripherals need to be already initialized before calling this function. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="a12fc697a01e1d04b91df358a472b5b84"></a><!-- doxytag: member="sensors.h::computeAngle" ref="a12fc697a01e1d04b91df358a472b5b84" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#a12fc697a01e1d04b91df358a472b5b84">computeAngle</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Compute the angle of the robot using the X and Y axes; the resulting angle is saved in the global variable "currentAngle". The angle refers to a classical reference system where the 0 points to the right, 90 to the top, 180 to the left and 270 to the bottom in a vertical wall. In order for the angle to be computed correctly, the robot has to be calibrated leaving it flat on the ground. Moreover this function update the robot motion plane (horizontal or vertical) based on the Z axis; this information is then used to switch between horizontal and vertical speed controller. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="a3d961b25677384479fcd0d413da8ef83"></a><!-- doxytag: member="sensors.h::initAccelerometer" ref="a3d961b25677384479fcd0d413da8ef83" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#a3d961b25677384479fcd0d413da8ef83">initAccelerometer</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Test which device is mounted on the robot and configure it. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="afe99cfb7d3e16bf36cc5d29da66ce8bc"></a><!-- doxytag: member="sensors.h::initADXL345" ref="afe99cfb7d3e16bf36cc5d29da66ce8bc" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="sensors_8h.html#afe99cfb7d3e16bf36cc5d29da66ce8bc">initADXL345</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Configure the ADXL345 accelerometer (2g sensitivity, 10 bits resolution). </p>
<dl class="retval"><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>configuration ok </td></tr>
    <tr><td class="paramname">1</td><td>communication error </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a00ac3777f39d082d583911fcedd3a302"></a><!-- doxytag: member="sensors.h::initMMA7455L" ref="a00ac3777f39d082d583911fcedd3a302" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="sensors_8h.html#a00ac3777f39d082d583911fcedd3a302">initMMA7455L</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Configure the MMA74565L accelerometer (2g sensitivity, 10 bits resolution). </p>
<dl class="retval"><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>configuration ok </td></tr>
    <tr><td class="paramname">1</td><td>communication error </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a9c7a0d4e693d6dd1fef72e28353324a1"></a><!-- doxytag: member="sensors.h::readAccelXY" ref="a9c7a0d4e693d6dd1fef72e28353324a1" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#a9c7a0d4e693d6dd1fef72e28353324a1">readAccelXY</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Request the X and Y values (10 bit data, 2's complement) and save them in their respective global variables accX and accY. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="ab3ef74e35beb0d06aefb2830ff49862d"></a><!-- doxytag: member="sensors.h::readAccelXYZ" ref="ab3ef74e35beb0d06aefb2830ff49862d" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#ab3ef74e35beb0d06aefb2830ff49862d">readAccelXYZ</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Request the X, Y and Z values (10 bit data, 2's complement) and save them in their respective global variables accX, accY and accZ. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="a2d993650e0a974e422727cb262f782ad"></a><!-- doxytag: member="sensors.h::readAccelXYZ_1" ref="a2d993650e0a974e422727cb262f782ad" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#a2d993650e0a974e422727cb262f782ad">readAccelXYZ_1</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="ab53b8f8a6ca993a60fc2377d0bfd2476"></a><!-- doxytag: member="sensors.h::readAccelXYZ_2" ref="ab53b8f8a6ca993a60fc2377d0bfd2476" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="sensors_8h.html#ab53b8f8a6ca993a60fc2377d0bfd2476">readAccelXYZ_2</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
</div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="sensors_8h.html">sensors.h</a>      </li>

    <li class="footer">Generated on Thu Dec 4 2014 08:30:51 for Elisa3 by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
